package mlz.b_collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//Collection的工具类
public class CollectionsDemo02 {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        Collections.addAll(names,"张三","李四","王五");
        System.out.println(names);//[张三, 李四, 王五]

        //对集合进行打乱元素顺序
        Collections.shuffle(names);
        System.out.println(names);

        //针对于List集合排序方法

        //默认排序 -> 自然排序 -> 实现Comparable接口
        Collections.sort(names);

        //比较器排序 -> 实现Comparator接口
        Collections.sort(names, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        });
        System.out.println(names);

    }
}













